<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>生成代码</title>
	<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	<script src="../../../component/layui/layui.js"></script>
	<script src="../../../component/pear/pear.js"></script>
</head>

<body class="pear-container">
	<div class="layui-card">
		<div class="layui-collapse">
			<div class="layui-colla-item">
				<h2 class="layui-colla-title">条件筛选<i class="layui-icon layui-colla-icon"></i></h2>
				<div class="layui-colla-content">
					<div class="layui-card-body">
						<form class="layui-form" action="" autocomplete="off" lay-filter="" id="FilterForm">
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">表名</label>
									<div class="layui-input-inline">
										<input type="text" name="content" placeholder="表名、说明模糊查询" class="layui-input">
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-input-block">
									<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit
										lay-filter="filter">
										<i class="layui-icon layui-icon-search"></i>
										查询
									</button>
									<button type="reset" class="pear-btn pear-btn-md">
										<i class="layui-icon layui-icon-refresh"></i>
										重置
									</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div class="layui-card">
		<div class="layui-card-body">
			<table id="table" lay-filter="table"></table>
		</div>
	</div>

</body>

</html>

<script type="text/html" id="toolbar">

</script>

<script type="text/html" id="bar">
	<button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="build"><i class="icon pear-icon pear-icon-code"></i></button>
</script>

<script>
	layui.use(['table', 'form', 'jquery', 'popup', 'common', 'context', 'permission', 'tableext'], function () {
		var table = layui.table;
		var form = layui.form;
		var $ = layui.jquery;
		var common = layui.common;
		var context = layui.context;
		var popup = layui.popup;

		var basePath = context.get("base-path");

		table.render({
			elem: '#table',
			url: basePath + '/api/system/buildcode/gettablelist',
			toolbar: '#toolbar',
			page: false,
			cols: [[
				{ title: '表名', field: 'name', width: 400 },
				{ title: '表描述', field: 'description', width: 800 },
				{ title: '操作', toolbar: '#bar', fixed: 'right', width: 180 }
			]],
			parseData: function (res) {
				return {
					"count": res.data.length,
					"statusCode": res.statusCode,
					"data": res.data
				};
			},
		});

		//table操作栏
		table.on('tool(table)', function (obj) {
			if (obj.event === 'build') {
				window.build(obj);
			}
		});

		//table工具栏
		table.on('toolbar(table)', function (obj) {
			if (obj.event === 'add') {
				window.add(obj);
			} else if (obj.event === 'refresh') {
				window.refresh(obj)
			}
		});

		//查询
		form.on('submit(filter)', function (data) {
			table.reload('table', {
				where: data.field,
			})
			return false;
		});


		window.build = function (obj) {
			layer.open({
				type: 2,
				title: '基本配置',
				shade: 0.1,
				area: ['500px', '350px'],
				content: 'build.html?tablename=' + obj.data['name'] + '&fresh=' + Math.random()
			});
		}
		window.refresh = function (obj) {
			table.reload('table')
		}
	})
</script>